/**
 * 数据库连接
 */

const mongoose = require('mongoose')
const config = require('./index')
const log4js = require('../utils/log4j')
// https://mongoosejs.com/docs/5.x/docs/connections.html mongoose v5.13版本链接数据库配置
mongoose.connect(config.URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    // useCreateIndex: true,
    // useFindAndModify: false
})

const db = mongoose.connection

db.on('open', () => {
    log4js.info('***数据库连接成功')
})

db.on('error', () => {
    log4js.error('***数据库连接失败')
})